

import React, { Component } from 'react';
import PropTypes from 'prop-types'

class PatientInfo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            hospital: this.props.hospital, //医院
            patientList: this.props.patientList, //患者基本信息
            diagnosis: this.props.diagnosis,
        };
    }


    //设置props值类型
    static propTypes = {
        diagnosis: PropTypes.string,
        hospital: PropTypes.string,
        patientList: PropTypes.object,

    }

    //初始化默认值
    static defaultProps = {
        diagnosis: '',
        hospital: '',
        patientList: {},
    }


    componentWillReceiveProps(nextProps, nextState) {
        /*
         * 医院或患者基本信息改变，则重新render
         * */
        if (nextProps.hospital !== nextState.hospital || nextProps.patientList !== nextState.patientList || nextProps.diagnosis !== nextState.diagnosis) {
            this.setState({
                hospital: nextProps.hospital, //医院
                patientList: nextProps.patientList, //患者基本信息
                diagnosis: nextProps.diagnosis,//诊断
            })
        }
    }

    getSexName(sex) {
        let sexName = "";
        if (sex == 1) {
            sexName = "男";
        } else if (sex == 2) {
            sexName = "女";
        }
        return sexName
    }


    render() {

        let { hospital, patientList, diagnosis } = this.state;


        return (
            <div className='patInfoContain'>
                <table className="patInfo">

                    <tbody>
                        <tr>
                            <td colSpan="4"><h1>{hospital}</h1></td>
                        </tr>
                        <tr>
                            <td colSpan="4"><h3>体温表</h3></td>
                        </tr>
                        <tr className="percent4">
                            <td><span className="btitle">姓名：</span><span className="bline">{patientList.name}</span></td>
                            <td><span className="btitle">性别：</span><span className="bline">{this.getSexName(patientList.sex)}</span></td>
                            <td><span className="btitle">年龄：</span><span className="bline">{patientList.age}</span></td>
                            <td><span className="btitle">入院日期：</span><span
                                className="bline">{patientList.inhosp_dateStr}</span></td>
                        </tr>
                        <tr className="percent4">
                            <td><span className="btitle">科室：</span><span className="bline">{patientList.wardName}</span></td>
                            <td><span className="btitle">床号：</span><span className="bline">{patientList.bed_no}</span></td>
                            {/* <td><span className="btitle">住院号：</span><span className="bline">{patientList.his_inhosp_id}</span></td> */}
                            <td><span className="btitle">疗养号：</span><span className="bline">{patientList.inhosp_no}</span></td>
                        </tr>

                        <tr>
                            <td colSpan="4">
                                <span className="btitle">诊断：</span>
                                <span className="btitle">{diagnosis}</span>

                            </td>

                        </tr>
                    </tbody>

                </table>


            </div>
        );
    }
}


export default PatientInfo;